package com.peaker.advertisingpro.utils

import android.util.Log
import com.ygkj.tasklib.cron4j.Scheduler

/**
 *  @ 作者 CODE_LYF
 *  @ 时间   2021/6/9.
 *  代码人生
 */
/**
 * 任务调度器管理类
 */
object SchedulerManager {
    var scheduler :Scheduler = Scheduler()
    var list: MutableSet<String> = mutableSetOf()

    fun addScheduler(timeStr: String, method: () -> Unit): String {

        val taskId = scheduler.schedule(timeStr) {
            method()
        }
        if(scheduler.isStarted.not()){
        scheduler.isDaemon = true
            scheduler.start()
        }

//        list.add(taskId)
        return taskId
    }

    fun addSchedulervolume(timeStr: String, value: String): String {

        Log.d("音量计划","方法添加了")
        val taskId = scheduler.schedule(timeStr) {
            SPUtil.putSP(Common.VOLUME,value)
            SmdtManagerUtils.smdtSetAndroidVolume(value.toInt())
            Log.d("音量计划","方法执行了")
        }
        if(scheduler.isStarted.not()){
        scheduler.isDaemon = true
            scheduler.start()
        }

        SchedulerUtils.list.add(taskId)

        return taskId
    }

    fun cleanTask(){
        list.forEach {
            scheduler.deschedule(it)
        }
    }

}